#include "lxz_config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "lxz_types.h"
#include "os_port.h"
#include "lxz_runlog.h"
#include "lxz_debug.h"
#include "lxz_ring.h"
#include "lxz_string.h"
#include "lxz_dstring.h"
#include "lxz_atc_req.h"
#include "lxz_urc_table.h"
#include "lxz_ccore_cmd.h"
#include "lxz_lsip_cmd.h"
#include "lxz_dbg_vmem.h"


typedef struct _lxzat_lsip_socket_t
{
    sint32 it_vsp_id;      /* Serial-Port ID */
    sint32 it_nif_id;      /* Network-Interface ID */
    uint16 ut_local_port;  /* The Port of local-host */
    uint16 ut_peer_port;   /* The Port of remote-host */
    uint32 it_link_type;   /* The type of link, TCP or UDP */
    sint32 it_socket_fd;   /* The file description of socket */
    sint32 it_socket_phase;/* The phase of socket, IDLE,OPEN... etc */
    sint32 it_flag_urcflag;    /* URC flag, OFF by default */
    sint32 it_mode_urcview;    /* TXT or PDU, valid when URC is valid */
    sint32 it_byte_urctryread;
    uint32 it_interval_urctryread;
    uint32 it_lasttick_urctryread;
    sint32 it_size_rxbuf;  /* The size of rxbuf */
    sint32 it_size_txbuf;  /* The size of txbuf */
    sint32 it_len_rxdata;  /* the length of data that stored in rxbuf */
    sint32 it_len_txdata;  /* the length of data that stored in txbuf */
    sint32 it_len_tryread;  /* the length of data that try to read */
    uint08 * pt_rxbuf;     /* pointer of rxbuf */
    uint08 * pt_txbuf;     /* pointer of rxbuf */
    uint08 * pt_peer_ip;   /* The IP-Address of remote-host */
	uint08 * pt_peer_url;  /* The Domain-Name of remote-host */
	uint08 * pt_local_ip;  /* The IP-Address of remote-host */
}lxzat_lsip_socket_t;

/*
 *  Description:
 *    A structure for saving parameters and result.
 *  Note: NONE
 */
typedef struct _lxzat_resp_mdnsquery_t
{
    sint32 i_got_flag;
    sint32 i_pdp_id;
    uint08 u_ipaddr_buf[LXZAT_SHLS_IPSTRING_MAX];
} lxzat_resp_mdnsquery_t;

static lxzat_lsip_socket_t gs_lsip_socket_pool[LXZAT_SHLS_MAX_NUM] = {0};

static sint32 lxzat_plus_mipurc_init(void * pctxt);
static sint32 lxzat_plus_mipurc_req(void * pctxt);
static sint32 lxzat_plus_mipurc_resp(void * pctxt);
static sint32 lxzat_plus_mipurc_reset(void * pctxt);

static sint32 lxzat_plus_mipcall_init(void * pctxt);
static sint32 lxzat_plus_mipcall_req(void * pctxt);
static sint32 lxzat_plus_mipcall_resp(void * pctxt);
static sint32 lxzat_plus_mipcall_reset(void * pctxt);

static sint32 lxzat_plus_mipopen_init(void * pctxt);
static sint32 lxzat_plus_mipopen_req(void * pctxt);
static sint32 lxzat_plus_mipopen_resp(void * pctxt);
static sint32 lxzat_plus_mipopen_reset(void * pctxt);

static sint32 lxzat_plus_mipmode_init(void * pctxt);
static sint32 lxzat_plus_mipmode_req(void * pctxt);
static sint32 lxzat_plus_mipmode_resp(void * pctxt);
static sint32 lxzat_plus_mipmode_reset(void * pctxt);

static sint32 lxzat_plus_mipwrite_init(void * pctxt);
static sint32 lxzat_plus_mipwrite_req(void * pctxt);
static sint32 lxzat_plus_mipwrite_resp(void * pctxt);
static sint32 lxzat_plus_mipwrite_reset(void * pctxt);

static sint32 lxzat_plus_mipread_init(void * pctxt);
static sint32 lxzat_plus_mipread_req(void * pctxt);
static sint32 lxzat_plus_mipread_resp(void * pctxt);
static sint32 lxzat_plus_mipread_reset(void * pctxt);

static sint32 lxzat_plus_mipreread_init(void * pctxt);
static sint32 lxzat_plus_mipreread_req(void * pctxt);
static sint32 lxzat_plus_mipreread_resp(void * pctxt);
static sint32 lxzat_plus_mipreread_reset(void * pctxt);

static sint32 lxzat_plus_mipput_init(void * pctxt);
static sint32 lxzat_plus_mipput_req(void * pctxt);
static sint32 lxzat_plus_mipput_resp(void * pctxt);
static sint32 lxzat_plus_mipput_reset(void * pctxt);

static sint32 lxzat_plus_mipget_init(void * pctxt);
static sint32 lxzat_plus_mipget_req(void * pctxt);
static sint32 lxzat_plus_mipget_resp(void * pctxt);
static sint32 lxzat_plus_mipget_reset(void * pctxt);

static sint32 lxzat_plus_mipclose_init(void * pctxt);
static sint32 lxzat_plus_mipclose_req(void * pctxt);
static sint32 lxzat_plus_mipclose_resp(void * pctxt);
static sint32 lxzat_plus_mipclose_reset(void * pctxt);

static sint32 lxzat_plus_mipquery_init(void * pctxt);
static sint32 lxzat_plus_mipquery_req(void * pctxt);
static sint32 lxzat_plus_mipquery_resp(void * pctxt);
static sint32 lxzat_plus_mipquery_reset(void * pctxt);

static sint32 lxzat_plus_mdnsquery_init(void * pctxt);
static sint32 lxzat_plus_mdnsquery_req(void * pctxt);
static sint32 lxzat_plus_mdnsquery_resp(void * pctxt);
static sint32 lxzat_plus_mdnsquery_reset(void * pctxt);

static sint32 lxzat_lsip_socket_f_close(sint32 i_id_socket);

static sint32 lxzat_callback_mipcall_f_exec(sint32 p1, sint32 p2);
static sint32 lxzat_callback_mipcall_f_exit(sint32 p1, sint32 p2);
static sint32 lxzat_task_mipcall_newtask(sint32 i_id_vspctxt, sint32 i_id_pdpctxt);

static sint32 lxzdata_plus_mipwrite_tcphandler(sint32 i_end_flag, void * pctxt);
static sint32 lxzdata_plus_mipwrite_udphandler(sint32 i_end_flag, void * pctxt);

static sint32 lxzat_callback_mipdata_tcplink_f_exec(sint32 p1, sint32 p2);
static sint32 lxzat_callback_mipdata_tcplink_f_exit(sint32 p1, sint32 p2);
static sint32 lxzat_task_mipdata_tcplink_newtask(sint32 i_id_socket, sint32 i_id_vspctxt);

static sint32 lxzat_callback_mipdata_udplink_f_exec(sint32 p1, sint32 p2);
static sint32 lxzat_callback_mipdata_udplink_f_exit(sint32 p1, sint32 p2);
static sint32 lxzat_task_mipdata_udplink_newtask(sint32 i_id_socket, sint32 i_id_vspctxt);

static sint32 lxzat_callback_mipclose_f_exec(sint32 p1, sint32 p2);
static sint32 lxzat_callback_mipclose_f_exit(sint32 p1, sint32 p2);
static sint32 lxzat_task_mipclose_newtask(sint32 i_id_socket, sint32 i_id_vspctxt);

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipurc =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPURC", 
    lxzat_plus_mipurc_init,
    lxzat_plus_mipurc_req,
    lxzat_plus_mipurc_resp,
    lxzat_plus_mipurc_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipcall =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPCALL", 
    lxzat_plus_mipcall_init,
    lxzat_plus_mipcall_req,
    lxzat_plus_mipcall_resp,
    lxzat_plus_mipcall_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipopen =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPOPEN", 
    lxzat_plus_mipopen_init,
    lxzat_plus_mipopen_req,
    lxzat_plus_mipopen_resp,
    lxzat_plus_mipopen_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipmode =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPMODE", 
    lxzat_plus_mipmode_init,
    lxzat_plus_mipmode_req,
    lxzat_plus_mipmode_resp,
    lxzat_plus_mipmode_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipwrite =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPWRITE", 
    lxzat_plus_mipwrite_init,
    lxzat_plus_mipwrite_req,
    lxzat_plus_mipwrite_resp,
    lxzat_plus_mipwrite_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipread =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPREAD", 
    lxzat_plus_mipread_init,
    lxzat_plus_mipread_req,
    lxzat_plus_mipread_resp,
    lxzat_plus_mipread_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipreread =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPREREAD", 
    lxzat_plus_mipreread_init,
    lxzat_plus_mipreread_req,
    lxzat_plus_mipreread_resp,
    lxzat_plus_mipreread_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipput =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPPUT", 
    lxzat_plus_mipput_init,
    lxzat_plus_mipput_req,
    lxzat_plus_mipput_resp,
    lxzat_plus_mipput_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipget =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPGET", 
    lxzat_plus_mipget_init,
    lxzat_plus_mipget_req,
    lxzat_plus_mipget_resp,
    lxzat_plus_mipget_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipclose =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPCLOSE", 
    lxzat_plus_mipclose_init,
    lxzat_plus_mipclose_req,
    lxzat_plus_mipclose_resp,
    lxzat_plus_mipclose_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mipquery =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MIPQUERY", 
    lxzat_plus_mipquery_init,
    lxzat_plus_mipquery_req,
    lxzat_plus_mipquery_resp,
    lxzat_plus_mipquery_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_plus_mdnsquery =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "+MDNSQUERY", 
    lxzat_plus_mdnsquery_init,
    lxzat_plus_mdnsquery_req,
    lxzat_plus_mdnsquery_resp,
    lxzat_plus_mdnsquery_reset
};

/*
 *  Description:
 *    The 2nd step of "AT+MIPWRITE".
 *  Param: p_data_buf, the pointer of data buffer;
 *  Param: i_data_len, the length of data in buffer;
 *  Param: i_end_flag, the end-flag recved or not;
 *  Param: pctxt, the descriptor of serial-port;
 *  Return: the number of bytes have been sent;
 *  Note: NONE
 */
static sint32 lxzdata_plus_mipwrite_tcphandler(sint32 i_end_flag, void * pctxt)
{
    sint32 i_nb_write = 0;

    sint32 i_nb_trywrite = 0;
    sint32 i_nb_read = 0;
    sint32 i_nb_tryread = 0;

    sint32 i_id_socket = 0;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    p_cur_spcfg = (lxzat_spcfg_t *)pctxt;
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_tcphandler,p_cur_spcfg is NULL!\r\n"));
        return i_nb_write;
    }
    
    i_nb_read = lxz_ring_f_getoption(p_cur_spcfg->pt_rx_ring, E_LRO_DATA_SIZE);
    if (i_nb_read < p_cur_spcfg->i_jump_length)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_tcphandler,i_nb_readable=%d,i_nb_expected=%d\r\n",i_nb_read, 
            p_cur_spcfg->i_jump_length));
        return i_nb_write;
    }
    
    p_cur_datacfg = p_cur_spcfg->pt_di_cfg;
    if (p_cur_datacfg == NULL)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_tcphandler,p_cur_datacfg is NULL!\r\n"));
        return i_nb_write;
    }
    
    i_id_socket = ((sint32)(p_cur_datacfg->p_param_ctxt));
    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
    if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_SENDING)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_tcphandler,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
        return E_LEC_ERR_NOT_ALLOWED;
    }
    
    i_nb_tryread = p_cur_spcfg->i_jump_length;
    i_nb_read = lxz_ring_f_read(p_cur_spcfg->pt_rx_ring, p_lsip_socket->pt_txbuf, i_nb_tryread);
    if (i_nb_read != i_nb_tryread)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_tcphandler,i_nb_read=%d,i_nb_tryread=%d\r\n",i_nb_read,
            i_nb_tryread));
        return i_nb_write;
    }

    i_nb_trywrite = i_nb_read;
    i_nb_write = osp_socket_f_write(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_txbuf, i_nb_trywrite);
    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_ACTIVE;
    
    free(p_cur_datacfg);
    p_cur_spcfg->pt_di_cfg = NULL;

    lxzat_rsp_f_printf(p_cur_spcfg->i_vsp_id, LXZAT_RSP_MODE_P1N1, "OK");
    
    lxzat_spcomm_f_clear(p_cur_spcfg->i_vsp_id);
    lxzat_spcomm_f_ChangeWorkMode(p_cur_spcfg->i_vsp_id,
        E_LSMX_ATC, LXZAT_END_CHAR_CR, LXZAT_END_CHAR_LF);
    return i_nb_write;
}

/*
 *  Description:
 *    The 2nd step of "AT+MIPWRITE".
 *  Param: p_data_buf, the pointer of data buffer;
 *  Param: i_data_len, the length of data in buffer;
 *  Param: i_end_flag, the end-flag recved or not;
 *  Param: pctxt, the descriptor of serial-port;
 *  Return: the number of bytes have been sent;
 *  Note: NONE
 */
static sint32 lxzdata_plus_mipwrite_udphandler(sint32 i_end_flag, void * pctxt)
{
    sint32 i_nb_write = 0;

    sint32 i_nb_trywrite = 0;
    sint32 i_nb_read = 0;
    sint32 i_nb_tryread = 0;

    sint32 i_id_socket = 0;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    p_cur_spcfg = (lxzat_spcfg_t *)pctxt;
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_udphandler,p_cur_spcfg is NULL!\r\n"));
        return i_nb_write;
    }
    
    i_nb_read = lxz_ring_f_getoption(p_cur_spcfg->pt_rx_ring, E_LRO_DATA_SIZE);
    if (i_nb_read < p_cur_spcfg->i_jump_length)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_udphandler,i_nb_readable=%d,i_nb_expected=%d\r\n",i_nb_read, 
            p_cur_spcfg->i_jump_length));
        return i_nb_write;
    }
    
    p_cur_datacfg = p_cur_spcfg->pt_di_cfg;
    if (p_cur_datacfg == NULL)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_udphandler,p_cur_datacfg is NULL!\r\n"));
        return i_nb_write;
    }
    
    i_id_socket = ((sint32)(p_cur_datacfg->p_param_ctxt));
    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
    if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_SENDING)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_udphandler,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
        return E_LEC_ERR_NOT_ALLOWED;
    }
    
    i_nb_tryread = p_cur_spcfg->i_jump_length;
    i_nb_read = lxz_ring_f_read(p_cur_spcfg->pt_rx_ring, p_lsip_socket->pt_txbuf, i_nb_tryread);
    if (i_nb_read != i_nb_tryread)
    {
        OS_DBG_LOG(("lxzdata_plus_mipwrite_udphandler,i_nb_read=%d,i_nb_tryread=%d\r\n",i_nb_read,
            i_nb_tryread));
        return i_nb_write;
    }

    i_nb_trywrite = i_nb_read;
    i_nb_write = osp_socket_f_writeto(p_lsip_socket->it_socket_fd, 
        p_lsip_socket->pt_txbuf, 
        i_nb_trywrite,
        p_lsip_socket->pt_peer_ip,
        p_lsip_socket->ut_peer_port);
    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_ACTIVE;
    
    free(p_cur_datacfg);
    p_cur_spcfg->pt_di_cfg = NULL;
    
    lxzat_rsp_f_printf(p_cur_spcfg->i_vsp_id, LXZAT_RSP_MODE_P1N1, "OK");
    
    lxzat_spcomm_f_clear(p_cur_spcfg->i_vsp_id);
    lxzat_spcomm_f_ChangeWorkMode(p_cur_spcfg->i_vsp_id,
        E_LSMX_ATC, LXZAT_END_CHAR_CR, LXZAT_END_CHAR_LF);
    return i_nb_write;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipurc_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipurc_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_flag_urcflag = LXZAT_FALSE;
    sint32 i_mode_urcview = LXZAT_FALSE;
    sint32 i_byte_urctryread = LXZAT_SHLS_URCREAD_DEF;
    sint32 i_interval_urctryread = 200;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipurc_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipurc_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            switch(p_cur_req->it_nb_param)
            {
            case 2:
                {
                    if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param1 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param2 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    i_id_socket = PARAM1(p_cur_req).it_number;
                    if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_id_socket=%d\r\n",i_id_socket));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
                    if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                        return E_LEC_ERR_NOT_ALLOWED;
                    }

                    i_flag_urcflag = PARAM2(p_cur_req).it_number;
                    if(i_flag_urcflag < 0 || i_flag_urcflag > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_flag_urcflag=%d\r\n",i_flag_urcflag));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_SET;
                    p_lsip_socket->it_flag_urcflag = i_flag_urcflag;
                    p_lsip_socket->it_mode_urcview = i_mode_urcview;
                    p_lsip_socket->it_byte_urctryread = i_byte_urctryread;
                    p_lsip_socket->it_interval_urctryread = i_interval_urctryread;
                    break; 
                }
            case 3:
                {
                    if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param1 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }
                    
                    if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param2 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param3 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    i_id_socket = PARAM1(p_cur_req).it_number;
                    if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_id_socket=%d\r\n",i_id_socket));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
                    if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                        return E_LEC_ERR_NOT_ALLOWED;
                    }

                    i_flag_urcflag = PARAM2(p_cur_req).it_number;
                    if(i_flag_urcflag < 0 || i_flag_urcflag > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_flag_urcflag=%d\r\n",i_flag_urcflag));
                        return E_LEC_ERR_P_RANGE;
                    }

                    i_mode_urcview = PARAM3(p_cur_req).it_number;
                    if(i_mode_urcview < 0 || i_mode_urcview > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_mode_urcview=%d\r\n",i_mode_urcview));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_SET;
                    p_lsip_socket->it_flag_urcflag = i_flag_urcflag;
                    p_lsip_socket->it_mode_urcview = i_mode_urcview;
                    p_lsip_socket->it_byte_urctryread = i_byte_urctryread;
                    p_lsip_socket->it_interval_urctryread = i_interval_urctryread;
                    break;
                }
            case 4:
                {
                    if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param1 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }
                    
                    if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param2 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }
                    
                    if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param3 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    if (PARAM4_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param4 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    i_id_socket = PARAM1(p_cur_req).it_number;
                    if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_id_socket=%d\r\n",i_id_socket));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
                    if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                        return E_LEC_ERR_NOT_ALLOWED;
                    }

                    i_flag_urcflag = PARAM2(p_cur_req).it_number;
                    if(i_flag_urcflag < 0 || i_flag_urcflag > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_flag_urcflag=%d\r\n",i_flag_urcflag));
                        return E_LEC_ERR_P_RANGE;
                    }

                    i_mode_urcview = PARAM3(p_cur_req).it_number;
                    if(i_mode_urcview < 0 || i_mode_urcview > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_mode_urcview=%d\r\n",i_mode_urcview));
                        return E_LEC_ERR_P_RANGE;
                    }

                    i_byte_urctryread = PARAM4(p_cur_req).it_number;
                    if(i_byte_urctryread < LXZAT_SHLS_URCREAD_MIN || i_byte_urctryread > LXZAT_SHLS_URCREAD_MAX)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_byte_urctryread=%d\r\n",i_byte_urctryread));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_SET;
                    p_lsip_socket->it_flag_urcflag = i_flag_urcflag;
                    p_lsip_socket->it_mode_urcview = i_mode_urcview;
                    p_lsip_socket->it_byte_urctryread = i_byte_urctryread;
                    p_lsip_socket->it_interval_urctryread = i_interval_urctryread;
                    break;
                }
            case 5:
                {
                    if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param1 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }
                    
                    if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param2 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }
                    
                    if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param3 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    if (PARAM4_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param4 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    if (PARAM5_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,param5 type is error!\r\n"));
                        return E_LEC_ERR_P_TYPE;
                    }

                    i_id_socket = PARAM1(p_cur_req).it_number;
                    if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_id_socket=%d\r\n",i_id_socket));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
                    if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                        return E_LEC_ERR_NOT_ALLOWED;
                    }

                    i_flag_urcflag = PARAM2(p_cur_req).it_number;
                    if(i_flag_urcflag < 0 || i_flag_urcflag > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_flag_urcflag=%d\r\n",i_flag_urcflag));
                        return E_LEC_ERR_P_RANGE;
                    }

                    i_mode_urcview = PARAM3(p_cur_req).it_number;
                    if(i_mode_urcview < 0 || i_mode_urcview > 1)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_mode_urcview=%d\r\n",i_mode_urcview));
                        return E_LEC_ERR_P_RANGE;
                    }

                    i_byte_urctryread = PARAM4(p_cur_req).it_number;
                    if(i_byte_urctryread < LXZAT_SHLS_URCREAD_MIN || i_byte_urctryread > LXZAT_SHLS_URCREAD_MAX)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_byte_urctryread=%d\r\n",i_byte_urctryread));
                        return E_LEC_ERR_P_RANGE;
                    }

                    i_interval_urctryread = PARAM5(p_cur_req).it_number;
                    if(i_interval_urctryread < LXZAT_SHLS_URCTIME_MIN || i_interval_urctryread > LXZAT_SHLS_URCTIME_MAX)
                    {
                        OS_DBG_LOG(("lxzat_plus_mipurc_req,i_interval_urctryread=%d\r\n",i_interval_urctryread));
                        return E_LEC_ERR_P_RANGE;
                    }

                    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_SET;
                    p_lsip_socket->it_flag_urcflag = i_flag_urcflag;
                    p_lsip_socket->it_mode_urcview = i_mode_urcview;
                    p_lsip_socket->it_byte_urctryread = i_byte_urctryread;
                    p_lsip_socket->it_interval_urctryread = i_interval_urctryread;
                    break;
                }
            default:
                {
                    OS_DBG_LOG(("lxzat_plus_mipurc_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                    return E_LEC_ERR_P_NB_PARAM;
                    break;
                }
            }

            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipurc_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_urc_view = LXZAT_FALSE;
    sint32 i_urc_read = LXZAT_SHLS_URCREAD_DEF;
    sint32 i_urc_time = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipurc_resp,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipurc_resp,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>[,URCFlag[,URCView[,URCRead[,URCTime]]]]",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
			
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
	
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipurc_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPCALL".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipcall_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPCALL".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipcall_req(void * pctxt)
{
    LXZAT_ERROR_CODE_E e_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_pdpcfg_t * p_cur_pdpcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipcall_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipcall_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_id_pdpctxt = 1;
            sint32 i_creg_isready = 0;
            sint32 i_pdp_isactive = 0;

            if (p_cur_req->it_nb_param != 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipcall_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }

            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipcall_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_creg_isready = lxzat_creg_f_getstatus(p_cur_spcfg->i_vsp_id);
            if(i_creg_isready == 0)
            {
                return E_LEC_SGCC_PDP_ACTIVE_REJECT;
            }
            
            lxzat_pdpinfo_f_getstatus(i_id_pdpctxt, &i_pdp_isactive);
            if (E_PDP_STATUS_ACTIVATING == i_pdp_isactive)
            {
                return E_LEC_SGCC_PDP_ACTIVE_REJECT;
            }
            if (E_PDP_STATUS_ACTIVATED == i_pdp_isactive)
            {
                return E_LEC_SGCC_PDP_ACTIVED;
            }
            
            lxzat_pdpinfo_f_active(p_cur_spcfg->i_vsp_id, i_id_pdpctxt);
            lxzat_task_mipcall_newtask(p_cur_spcfg->i_vsp_id, i_id_pdpctxt);

            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }

    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }

    default:
        {
            e_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return e_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPCALL".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipcall_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipcall_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipcall_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }

    case LXZAT_REQ_TYPE_READ:
        {
            sint32 i = 0;
            lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

            while (i < 6)
            {
                p_cur_pdpinfo = lxzat_pdpinfo_f_get(i + 1);
                if (E_PDP_STATUS_ACTIVATED == p_cur_pdpinfo->it_pdp_state)
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,1,\"%s\"",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i,
                        p_cur_pdpinfo->pt_ip_host);
                }

                i = i + 1;
            }
            break;
        }

    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <IsActive>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            break;
        }


    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPCALL".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipcall_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipopen_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipopen_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

	sint32 i_op_status = LXZAT_FALSE;
    sint32 i_id_socket = 0;
    sint32 i_nb_bytes = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipopen_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipopen_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 4)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,param2 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,param3 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }

            if (PARAM4_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,param4 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_socket = PARAM1(p_lxzat_ctxt->pt_req_data).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,i_id_socket=%d\r\n", i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }

            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            if (   (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
                && (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_SET))
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_req,i_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                return E_LEC_ERR_NOT_ALLOWED;
            }

            /* Initialize lsip-socket, make sure all states are controlled */
            if (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_IDLE)
            {
                lxzat_lsip_socket_f_close(i_id_socket);
                p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_SET;
            }
			
            p_lsip_socket->pt_rxbuf = (uint08 *)malloc(LXZAT_SHLS_TRYREAD_MAX);
            if(p_lsip_socket->pt_rxbuf == NULL)
            {
                lxzat_lsip_socket_f_close(i_id_socket);

                OS_DBG_LOG(("lxzat_plus_mipopen_req,pt_rxbuf malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }
			
            p_lsip_socket->pt_txbuf = (uint08 *)malloc(LXZAT_SHLS_TRYWRITE_MAX);
            if(p_lsip_socket->pt_txbuf == NULL)
            {
				lxzat_lsip_socket_f_close(i_id_socket);
				
                OS_DBG_LOG(("lxzat_plus_mipopen_req,pt_txbuf malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            p_lsip_socket->pt_peer_ip = (uint08 *)malloc(LXZAT_SHLS_IPSTRING_MAX);
            if(p_lsip_socket->pt_peer_ip == NULL)
            {
				lxzat_lsip_socket_f_close(i_id_socket);
				
                OS_DBG_LOG(("lxzat_plus_mipopen_req,pt_peer_ip malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            p_lsip_socket->pt_peer_url = (uint08 *)malloc(LXZAT_SHLS_URLSTRING_MAX);
            if(p_lsip_socket->pt_peer_url == NULL)
            {
				lxzat_lsip_socket_f_close(i_id_socket);

                OS_DBG_LOG(("lxzat_plus_mipopen_req,pt_peer_url malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            p_lsip_socket->pt_local_ip = (uint08 *)malloc(LXZAT_SHLS_IPSTRING_MAX);
            if(p_lsip_socket->pt_local_ip == NULL)
            {
				lxzat_lsip_socket_f_close(i_id_socket);

                OS_DBG_LOG(("lxzat_plus_mipopen_req,pt_local_ip malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            if(0 == strcasecmp((char *)(PARAM2(p_cur_req).pt_str->pt_string), "UDP"))
            {
                p_lsip_socket->it_link_type = E_SHLS_LINK_UDP;
            }
            else if(0 == strcasecmp((char *)(PARAM2(p_cur_req).pt_str->pt_string), "TCP"))
            {
                p_lsip_socket->it_link_type = E_SHLS_LINK_TCP;
            }
            else
            {
				lxzat_lsip_socket_f_close(i_id_socket);

                OS_DBG_LOG(("lxzat_plus_mipopen_req,i_link_type=%s\r\n",PARAM2(p_cur_req).pt_str->pt_string));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_bytes = PARAM3(p_cur_req).pt_str->it_length;
            if (i_nb_bytes > LXZAT_SHLS_URLSTRING_MAX)
            {
				lxzat_lsip_socket_f_close(i_id_socket);

                OS_DBG_LOG(("lxzat_plus_mipopen_req,i_url_length=%d\r\n", i_nb_bytes));
                return E_LEC_ERR_P_RANGE;
            }
            p_lsip_socket->pt_peer_url = (uint08 *)malloc(i_nb_bytes + 1);
            memset(p_lsip_socket->pt_peer_url, 0, i_nb_bytes + 1);
            strcpy(p_lsip_socket->pt_peer_url, PARAM3(p_cur_req).pt_str->pt_string);
            
            p_lsip_socket->ut_peer_port = (uint16)PARAM4(p_cur_req).it_number;
            if((p_lsip_socket->ut_peer_port < 0) || (p_lsip_socket->ut_peer_port > 0xFFFF))
            {
				lxzat_lsip_socket_f_close(i_id_socket);

                OS_DBG_LOG(("lxzat_plus_mipopen_req,u_peer_port=%d\r\n", p_lsip_socket->ut_peer_port));
                return E_LEC_ERR_P_RANGE;
            }

            switch(p_lsip_socket->it_link_type)
            {
            case E_SHLS_LINK_TCP:
                {
					i_op_status = osp_gethostbyname(p_lsip_socket->pt_peer_url ,p_lsip_socket->pt_peer_ip);
                    if(LXZAT_TRUE != i_op_status)
                    {
						lxzat_lsip_socket_f_close(i_id_socket);

                        OS_DBG_LOG(("lxzat_plus_mipopen_req,osp_gethostbyname error\r\n"));
                        return E_LEC_SGCC_DNS_TIMEOUT;
                    }

                    p_lsip_socket->it_socket_fd = osp_socket_f_open(2/*AF_INET*/, 1/*SOCK_STREAM*/,0);
                    if (p_lsip_socket->it_socket_fd == LXZAT_SHLS_INVALID_FD)
                    {
						lxzat_lsip_socket_f_close(i_id_socket);
						
						OS_DBG_LOG(("lxzat_plus_mipopen_req,osp_socket_f_open error\r\n"));
						return E_LEC_ERR_NET_SOCKET_INVALID;
                    }
					
                    i_op_status = osp_socket_f_connect(p_lsip_socket->it_socket_fd,p_lsip_socket->pt_peer_ip,p_lsip_socket->ut_peer_port);
                    if (i_op_status != LXZAT_TRUE)
                    {
						lxzat_lsip_socket_f_close(i_id_socket);
						
						OS_DBG_LOG(("lxzat_plus_mipopen_req,osp_socket_f_connect error\r\n"));
						return E_LEC_ERR_NET_CONNECT_TIMEOUT;
                    }

                    p_lsip_socket->it_size_rxbuf = LXZAT_SHLS_TRYREAD_MAX;
                    p_lsip_socket->it_size_txbuf = LXZAT_SHLS_TRYWRITE_MAX;
                    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_ACTIVE;

                    /* When URC is on, start *mipdata-tcpclient* task */
                    if (p_lsip_socket->it_flag_urcflag == LXZAT_TRUE)
                    {
                        lxzat_task_mipdata_tcplink_newtask(i_id_socket, p_cur_spcfg->i_vsp_id);
                    }
                    else
                    {
                        lxzat_task_mipclose_newtask(i_id_socket, p_cur_spcfg->i_vsp_id);
                    }
                    break;
                }
            case E_SHLS_LINK_UDP:
                {
					i_op_status = osp_gethostbyname(p_lsip_socket->pt_peer_url ,p_lsip_socket->pt_peer_ip);
                    if(LXZAT_TRUE != i_op_status)
                    {
						lxzat_lsip_socket_f_close(i_id_socket);

                        OS_DBG_LOG(("lxzat_plus_mipopen_req,osp_gethostbyname error\r\n"));
                        return E_LEC_SGCC_DNS_TIMEOUT;
                    }

                    p_lsip_socket->it_socket_fd = osp_socket_f_open(2/*AF_INET*/, 2/*SOCK_DGRAM*/,0);
                    if (p_lsip_socket->it_socket_fd == LXZAT_SHLS_INVALID_FD)
                    {
						lxzat_lsip_socket_f_close(i_id_socket);
						
						OS_DBG_LOG(("lxzat_plus_mipopen_req,osp_socket_f_open error\r\n"));
						return E_LEC_ERR_NET_SOCKET_INVALID;

                    }

                    memset(p_lsip_socket->pt_local_ip, 0, LXZAT_SHLS_IPSTRING_MAX);
                    i_op_status = osp_socket_f_bind(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_local_ip, 0);
                    if (i_op_status != 1)
                    {
                        lxzat_lsip_socket_f_close(i_id_socket);
						
                        OS_DBG_LOG(("lxzat_plus_mipopen_req, osp_socket_f_bind error\r\n"));
                        return E_LEC_ERR_NET_SOCKET_BIND;
                    }

                    p_lsip_socket->it_size_rxbuf = LXZAT_SHLS_TRYREAD_MAX;
                    p_lsip_socket->it_size_txbuf = LXZAT_SHLS_TRYWRITE_MAX;
                    p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_ACTIVE;
                    break;
                }
            default:
                {
					OS_DBG_LOG(("lxzat_plus_mipopen_req,i_link_type=%d\r\n",p_lsip_socket->it_link_type));
					return E_LEC_SGCC_UNKNOWN;

                    break;
                }
            }
            break;
        }
        
    default:
        {
            break;
        }
    }

    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipopen_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipopen_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipopen_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
			sint32 i_op_status = LXZAT_TRUE;
			
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipopen_resp,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d,%d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_id_socket,
                i_op_status);

            break;
        }

    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }

    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<\"TCP\"|\"UDP\">,<\"IP\">,<Port>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
        
    default:
        {
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipopen_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPMODE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipmode_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPMODE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipmode_req(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The response handler of "AT+MIPMODE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipmode_resp(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPMODE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipmode_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPWRITE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipwrite_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPWRITE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipwrite_req(void * pctxt)
{
	sint32 i_err_code = E_LEC_OK;
	sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
	
	lxzat_req_t * p_cur_req = NULL;
	lxzat_spcfg_t * p_cur_spcfg = NULL;
	lxzdata_info_t * p_cur_datacfg = NULL;
	lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
	
	sint32 i_id_socket = 0;
	sint32 i_nb_trywrite = 0;
	sint32 i_op_status = 0;
	lxzat_lsip_socket_t * p_lsip_socket = NULL;
	
	if (p_lxzat_ctxt == NULL)
	{
		OS_DBG_LOG(("lxzat_plus_mipwrite_req,p_lxzat_ctxt is NULL!\r\n"));
		return E_LEC_ERR_UNKNOWN;
	}
	
	p_cur_req = p_lxzat_ctxt->pt_req_data;
	p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
	if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
	{
		OS_DBG_LOG(("lxzat_plus_mipwrite_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
		return E_LEC_ERR_UNKNOWN;
	}
	
	i_req_type = p_cur_req->it_req_type;
	switch(i_req_type)
	{
	case LXZAT_REQ_TYPE_SET:
		{
			if (p_cur_req->it_nb_param != 2)
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
				return E_LEC_ERR_P_NB_PARAM;
			}
			
			if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,param1 type error!\r\n"));
				return E_LEC_ERR_P_TYPE;
			}
			
			if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,param2 type error!\r\n"));
				return E_LEC_ERR_P_TYPE;
			}
			
			i_id_socket= PARAM1(p_cur_req).it_number;
			if ((i_id_socket < 0) || (i_id_socket > LXZAT_SHLS_MAX_NUM))
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,i_id_socket=%d\r\n",i_id_socket));
				return E_LEC_ERR_P_RANGE;
			}
			
			p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
			if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_ACTIVE)
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,i_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
				return E_LEC_ERR_NOT_ALLOWED;
			}
			
			i_nb_trywrite= PARAM2(p_cur_req).it_number;
			if(i_nb_trywrite < LXZAT_SHLS_TRYWRITE_MIN || i_nb_trywrite > LXZAT_SHLS_TRYWRITE_MAX)
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,i_nb_trywrite=%d\r\n",i_nb_trywrite));
				return E_LEC_ERR_P_RANGE;
			}
			
			p_cur_datacfg = (lxzdata_info_t *)malloc(sizeof(lxzdata_info_t));
			if (p_cur_datacfg == NULL)
			{
				OS_DBG_LOG(("lxzat_plus_mipwrite_req,p_cur_datacfg malloc error!\r\n"));
				return E_LEC_ERR_MEM_MALLOC;
			}
			
            switch(p_lsip_socket->it_link_type)
            {
            case E_SHLS_LINK_TCP:
                {
                    memset(p_cur_datacfg, 0, sizeof(lxzdata_info_t));
                    p_cur_datacfg->fp_data_handler = lxzdata_plus_mipwrite_tcphandler;
                    p_cur_datacfg->p_param_ctxt = (uint32 *)i_id_socket;
                    break;
                }
                
            case E_SHLS_LINK_UDP:
                {
                    memset(p_cur_datacfg, 0, sizeof(lxzdata_info_t));
                    p_cur_datacfg->fp_data_handler = lxzdata_plus_mipwrite_udphandler;
                    p_cur_datacfg->p_param_ctxt = (uint32 *)i_id_socket;
                    break;
                }
                
            default:
                {
                    OS_DBG_LOG(("lxzat_plus_mipopen_req,i_link_type=%d\r\n",p_lsip_socket->it_link_type));
                    return E_LEC_SGCC_UNKNOWN;
                    break;
                }
            }
			
			p_cur_spcfg->i_jump_length = i_nb_trywrite;
			p_cur_spcfg->pt_di_cfg = p_cur_datacfg;
			p_cur_spcfg->i_echo_auxiliary = LXZAT_FALSE;
			lxzat_spcomm_f_clear(p_cur_spcfg->i_vsp_id);
			lxzat_spcomm_f_ChangeWorkMode(p_cur_spcfg->i_vsp_id,
				E_LSMA_FIXED_LEN, 0, 0);
			
			p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_SENDING;
			lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
				LXZAT_RSP_MODE_P1N1,
				"%s","> ");
			break;
		}
	case LXZAT_REQ_TYPE_READ:
		{
			break;
		}
	case LXZAT_REQ_TYPE_TEST:
		{
			break;
		}
	default:
		{
			i_err_code = E_LEC_ERR_UNSUPPORTED;
			break;
		}
	}
	
	return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPWRITE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipwrite_resp(void * pctxt)
{
	sint32 i_err_code = E_LEC_OK;
	
	sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
	lxzat_req_t * p_cur_req = NULL;
	lxzat_spcfg_t * p_cur_spcfg = NULL;
	lxzdata_info_t * p_cur_datacfg = NULL;
	lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
	
	if (p_lxzat_ctxt == NULL)
	{
		OS_DBG_LOG(("lxzat_plus_mipwrite_resp,p_lxzat_ctxt is NULL!\r\n"));
		return E_LEC_ERR_UNKNOWN;
	}
	
	p_cur_req = p_lxzat_ctxt->pt_req_data;
	p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
	if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
	{
		OS_DBG_LOG(("lxzat_plus_mipwrite_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
		return E_LEC_ERR_UNKNOWN;
	}
	
	i_req_type = p_cur_req->it_req_type;
	switch(i_req_type)
	{
	case LXZAT_REQ_TYPE_SET:
		{
			i_err_code = E_LEC_OK_NOTHING;
			break;
		}
	case LXZAT_REQ_TYPE_READ:
		{
			break;
		}
	case LXZAT_REQ_TYPE_TEST:
		{
			lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
				LXZAT_RSP_MODE_P1N0,
				"%s: <SocketID>,<TryWriteLength>",
				p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
			
			break;
		}
	default:
		{
			i_err_code = E_LEC_ERR_UNKNOWN;
			break;
		}
	}
	
	return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPWRITE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipwrite_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipread_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipread_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_nb_realread = 0;
    sint32 i_md_display = 0;
    sint32 i_nb_tryread = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipread_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipread_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 2)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_req,param2 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_req,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_tryread= PARAM2(p_cur_req).it_number;
            if(i_nb_tryread < LXZAT_SHLS_TRYREAD_MIN || i_nb_tryread > LXZAT_SHLS_TRYREAD_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_req,i_nb_tryread=%d\r\n",i_nb_tryread));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            if (p_lsip_socket->it_socket_phase < E_SHLS_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                return E_LEC_ERR_NOT_ALLOWED;
            }
            
            /* When URC is off, "+MIPREAD" is valid */
            if (p_lsip_socket->it_flag_urcflag == LXZAT_FALSE)
            {
                switch(p_lsip_socket->it_link_type)
                {
                case E_SHLS_LINK_TCP:
                    {
                        i_nb_realread = osp_socket_f_read(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_rxbuf, i_nb_tryread);
                        p_lsip_socket->it_len_rxdata = i_nb_realread;
                        p_lsip_socket->it_len_tryread = i_nb_tryread;
                        break;
                    }
                case E_SHLS_LINK_UDP:
                    {
                        i_nb_realread = osp_socket_f_readfrom(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_rxbuf, i_nb_tryread);
                        p_lsip_socket->it_len_rxdata = i_nb_realread;
                        p_lsip_socket->it_len_tryread = i_nb_tryread;
                        break;
                    }
                default:
                    {
                        break;
                    }
                }
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipread_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_nb_realread = 0;
    sint32 i_md_display = 0;
    sint32 i_nb_tryread = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipread_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipread_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_resp,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_UNSUPPORTED;
            }
            
            i_nb_tryread= PARAM2(p_cur_req).it_number;
            if(i_nb_tryread < LXZAT_SHLS_TRYREAD_MIN || i_nb_tryread > LXZAT_SHLS_TRYREAD_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipread_resp, i_nb_tryread:=%d\r\n",i_nb_tryread));
                return E_LEC_ERR_UNSUPPORTED;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            i_nb_realread = p_lsip_socket->it_len_rxdata;
            
            if (i_nb_realread > 0)
            {
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P1N1,
                    "%s: %d,%d",
                    p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                    i_id_socket,
                    i_nb_realread);
                lxzat_rsp_f_printfbin(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P0N0,
                    p_lsip_socket->pt_rxbuf,
                    i_nb_realread);
            }
            else
            {
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P1N0,
                    "%s: %d,%d",
                    p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                    i_id_socket,
                    0);
            }
            
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<TryReadLength>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
        
    default:
        {
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipread_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPREREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipreread_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPREREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipreread_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_nb_realread = 0;
    sint32 i_md_display = 0;
    sint32 i_nb_tryread = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipget_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipget_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 3)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,param2 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,param3 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_md_display = PARAM2(p_cur_req).it_number;
            if(i_md_display < 0 || i_md_display > 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_md_display=%d\r\n",i_md_display));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_tryread= PARAM3(p_cur_req).it_number;
            if(i_nb_tryread < LXZAT_SHLS_TRYREAD_MIN || i_nb_tryread > LXZAT_SHLS_TRYREAD_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_nb_tryread=%d\r\n",i_nb_tryread));
                return E_LEC_ERR_P_RANGE;
            }

            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            if (p_lsip_socket->it_socket_phase < E_SHLS_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                return E_LEC_ERR_NOT_ALLOWED;
            }

            /* When URC is on, "+MIPGET" is invalid */
            if (p_lsip_socket->it_flag_urcflag == LXZAT_TRUE)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,it_flag_urcflag=%d\r\n", p_lsip_socket->it_flag_urcflag));
                return E_LEC_ERR_NOT_ALLOWED;
            }

            if (i_nb_tryread != p_lsip_socket->it_len_tryread)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_nb_tryread=%d,i_nb_lasttryread=%d\r\n",i_nb_tryread,p_lsip_socket->it_len_tryread));
                return E_LEC_ERR_P_RANGE;
            }

            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPREREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipreread_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_nb_realread = 0;
    sint32 i_md_display = 0;
    sint32 i_nb_tryread = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipget_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipget_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_resp,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_UNSUPPORTED;
            }
            
            i_md_display = PARAM2(p_cur_req).it_number;
            if(i_md_display < 0 || i_md_display > 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_resp,i_md_display=%d\r\n",i_md_display));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_tryread= PARAM3(p_cur_req).it_number;
            if(i_nb_tryread < LXZAT_SHLS_TRYREAD_MIN || i_nb_tryread > LXZAT_SHLS_TRYREAD_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_resp, i_nb_tryread:=%d\r\n",i_nb_tryread));
                return E_LEC_ERR_UNSUPPORTED;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            i_nb_realread = p_lsip_socket->it_len_rxdata;
            
            if (i_nb_realread > 0)
            {
                if (i_md_display == 1/*LXZAT_VIEW_MODE_TXT*/)
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N1,
                        "%s: %d,%d,%d,0xFFFF",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_md_display,
                        i_nb_realread);
                    lxzat_rsp_f_printfhex(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P0N0,
                        p_lsip_socket->pt_rxbuf,
                        i_nb_realread);
                }
                else
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N1,
                        "%s: %d,%d,%d,0xFFFF",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_md_display,
                        i_nb_realread);
                    lxzat_rsp_f_printfbin(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P0N0,
                        p_lsip_socket->pt_rxbuf,
                        i_nb_realread);
                }
            }
            else
            {
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P1N0,
                    "%s: %d,%d,%d,0xFFFf",
                    p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                    i_id_socket,
                    i_md_display,
                    0);
            }
            
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<ViewMode>,<TryGetLength>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
        
    default:
        {
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPREREAD".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipreread_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPPUT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipput_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPPUT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipput_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    sint32 i_nb_put = 0;
    sint32 i_id_socket = 0;
    sint32 i_string_type = 0;
    sint32 i_string_len = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipput_req,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipput_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 3)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,param2 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,param3 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_string_type= PARAM2(p_cur_req).it_number;
            if(i_string_type < 0 || i_string_type > 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,i_string_type=%d\r\n",i_string_type));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,i_socket_phase=%d\r\n",p_lsip_socket->it_socket_phase));
                return E_LEC_ERR_P_OTHER;
            }
            
            i_string_len = lxz_dstring_getlength(PARAM3(p_cur_req).pt_str);
            if(i_string_len < LXZAT_SHLS_TRYWRITE_MIN || i_string_len > LXZAT_SHLS_TRYWRITE_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_req,i_nb_trywrite=%d\r\n",i_string_len));
                return E_LEC_ERR_P_LENGTH;
            }
            
            memset(p_lsip_socket->pt_txbuf, 0, p_lsip_socket->it_size_txbuf);
            lxz_dstring_get(PARAM3(p_cur_req).pt_str, p_lsip_socket->pt_txbuf, p_lsip_socket->it_size_txbuf);
            p_lsip_socket->it_len_txdata = strlen(p_lsip_socket->pt_txbuf);
            
            if (i_string_type == 1)
            {
                sint32 i_op_status = 0;
                
                i_op_status = lxz_string_f_hex2bin(p_lsip_socket->pt_txbuf, p_lsip_socket->it_len_txdata, 
                    p_lsip_socket->pt_txbuf);
                if (0 == i_op_status)
                {
                    OS_DBG_LOG(("lxzat_plus_mipput_req,lxz_string_f_hex2bin error!\r\n"));
                    return E_LEC_ERR_P_OTHER;
                }
                
                p_lsip_socket->it_len_txdata = (p_lsip_socket->it_len_txdata >> 1);
            }

            switch(p_lsip_socket->it_link_type)
            {
            case E_SHLS_LINK_TCP:
                {
                    i_nb_put = osp_socket_f_write(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_txbuf, p_lsip_socket->it_len_txdata);
                    break;
                }
            case E_SHLS_LINK_UDP:
                {
                    i_nb_put = osp_socket_f_writeto(p_lsip_socket->it_socket_fd, 
                        p_lsip_socket->pt_txbuf, 
                        p_lsip_socket->it_len_txdata,
                        p_lsip_socket->pt_peer_ip,
                        p_lsip_socket->ut_peer_port);
                    break;
                }
            default:
                {
                    break;
                }
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}


/*
 *  Description:
 *    The response handler of "AT+MIPPUT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipput_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    sint32 i_nb_put = 0;
    sint32 i_id_socket = 0;
    sint32 i_string_type = 0;
    sint32 i_string_len = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipput_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipput_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;

    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_cur_offset = 0;
            
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipput_resp,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d,%d,%d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_id_socket,
                p_lsip_socket->it_len_txdata,
                i_cur_offset);
            
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<StringType>,<\"StringContent\">",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
    
    return i_err_code;
}


/*
 *  Description:
 *    The reset handler of "AT+MIPPUT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipput_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPGET".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipget_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPGET".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipget_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_md_display = 0;
    sint32 i_nb_tryread = 0;
    sint32 i_nb_realread = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipget_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipget_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 3)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,param2 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,param3 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_md_display = PARAM2(p_cur_req).it_number;
            if(i_md_display < 0 || i_md_display > 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_md_display=%d\r\n",i_md_display));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_tryread= PARAM3(p_cur_req).it_number;
            if(i_nb_tryread < LXZAT_SHLS_TRYREAD_MIN || i_nb_tryread > LXZAT_SHLS_TRYREAD_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,i_nb_tryread=%d\r\n",i_nb_tryread));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            if (p_lsip_socket->it_socket_phase < E_SHLS_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                return E_LEC_ERR_NOT_ALLOWED;
            }

            /* When URC is on, "+MIPGET" is invalid */
            if (p_lsip_socket->it_flag_urcflag == LXZAT_TRUE)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_req,it_flag_urcflag=%d\r\n", p_lsip_socket->it_flag_urcflag));
                return E_LEC_ERR_NOT_ALLOWED;
            }

            /* When URC is off, "+MIPGET" is valid */
            if (p_lsip_socket->it_flag_urcflag == LXZAT_FALSE)
            {
                switch(p_lsip_socket->it_link_type)
                {
                case E_SHLS_LINK_TCP:
                    {
                        i_nb_realread = osp_socket_f_read(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_rxbuf, i_nb_tryread);
                        p_lsip_socket->it_len_rxdata = i_nb_realread;
                        p_lsip_socket->it_len_tryread = i_nb_tryread;
                        break;
                    }
                case E_SHLS_LINK_UDP:
                    {
                        i_nb_realread = osp_socket_f_readfrom(p_lsip_socket->it_socket_fd, p_lsip_socket->pt_rxbuf, i_nb_tryread);
                        p_lsip_socket->it_len_rxdata = i_nb_realread;
                        p_lsip_socket->it_len_tryread = i_nb_tryread;
                        break;
                    }
                default:
                    {
                        break;
                    }
                }
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPGET".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipget_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_nb_realread = 0;
    sint32 i_md_display = 0;
    sint32 i_nb_tryread = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipget_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipget_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_resp,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_UNSUPPORTED;
            }
            
            i_md_display = PARAM2(p_cur_req).it_number;
            if(i_md_display < 0 || i_md_display > 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_resp,i_md_display=%d\r\n",i_md_display));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_tryread= PARAM3(p_cur_req).it_number;
            if(i_nb_tryread < LXZAT_SHLS_TRYREAD_MIN || i_nb_tryread > LXZAT_SHLS_TRYREAD_MAX)
            {
                OS_DBG_LOG(("lxzat_plus_mipget_resp, i_nb_tryread:=%d\r\n",i_nb_tryread));
                return E_LEC_ERR_UNSUPPORTED;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            i_nb_realread = p_lsip_socket->it_len_rxdata;
            
            if (i_nb_realread > 0)
            {
                if (i_md_display == 1/*LXZAT_VIEW_MODE_TXT*/)
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N1,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_md_display,
                        i_nb_realread);
                    lxzat_rsp_f_printfhex(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P0N0,
                        p_lsip_socket->pt_rxbuf,
                        i_nb_realread);
                }
                else
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N1,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_md_display,
                        i_nb_realread);
                    lxzat_rsp_f_printfbin(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P0N0,
                        p_lsip_socket->pt_rxbuf,
                        i_nb_realread);
                }
            }
            else
            {
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P1N0,
                    "%s: %d,%d,%d",
                    p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                    i_id_socket,
                    i_md_display,
                    0);
            }
            
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<ViewMode>,<TryGetLength>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
        
    default:
        {
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPGET".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipget_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipclose_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipclose_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
	
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
	
    sint32 i_id_socket = 0;
    sint32 i_md_display = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
	
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipclose_req,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipclose_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipclose_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
			
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipclose_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
			
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipclose_req,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
			
			lxzat_lsip_socket_f_close(i_id_socket);
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
	
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MIPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipclose_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
	
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
	
    sint32 i_id_socket = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
	
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipclose_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipclose_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            sint32 i_status_socket = 0;

            p_lsip_socket = &(gs_lsip_socket_pool[0]);
            i_status_socket = 0;
            if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
            {
                i_status_socket = 1;
            }

            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_status_socket);
            
            i_id_socket = 1;
            while (i_id_socket < LXZAT_SHLS_MAX_NUM)
            {
                p_lsip_socket = &(gs_lsip_socket_pool[0]);
                i_status_socket = 0;
                if (p_lsip_socket->it_socket_phase != E_SHLS_SOCKET_IDLE)
                {
                    i_status_socket = 1;
                }
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P0N0,
                    ",%d",
                    i_status_socket);

                i_id_socket = i_id_socket + 1;
            }

            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
			
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
	
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipclose_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MIPQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipquery_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT+MIPQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipquery_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_query_type = 0;
    sint32 i_urc_view = LXZAT_FALSE;
    sint32 i_urc_read = LXZAT_SHLS_URCREAD_DEF;
    sint32 i_urc_time = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipquery_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipquery_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 2)
            {
                OS_DBG_LOG(("lxzat_plus_mipquery_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }

            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipquery_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mipquery_req,param2 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_socket = PARAM1(p_cur_req).it_number;
            if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_plus_mipquery_req,i_id_socket=%d\r\n",i_id_socket));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
            if (p_lsip_socket->it_socket_phase < E_SHLS_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_plus_mipquery_req,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
                return E_LEC_ERR_NOT_ALLOWED;
            }
            
            i_query_type = PARAM2(p_cur_req).it_number;
            if(i_urc_view < 0 || i_urc_view > 1)
            {
                OS_DBG_LOG(("lxzat_plus_mipquery_req,i_urc_view=%d\r\n",i_urc_view));
                return E_LEC_ERR_P_RANGE;
            }

            switch(i_query_type)
            {
            case E_SHLS_QUERY_STATUS:
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        p_lsip_socket->it_socket_phase);
                    break;
                }
            case E_SHLS_QUERY_URCINFO:
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d,%d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        p_lsip_socket->it_flag_urcflag,
                        p_lsip_socket->it_mode_urcview,
                        p_lsip_socket->it_byte_urctryread,
                        p_lsip_socket->it_interval_urctryread);
                    break;
                }
            case E_SHLS_QUERY_TCPSNDBUF:
                {
					sint32 i_txbuf_size = 0;
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        i_txbuf_size);
                    break;
                }
            case E_SHLS_QUERY_TCPSNDDATA:
                {
					sint32 i_txdata_size = 0;
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        i_txdata_size);
                    break;
                }
            case E_SHLS_QUERY_TCPSNDFREE:
                {
					sint32 i_txfree_size = 0;
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        i_txfree_size);
                    break;
                }
            case E_SHLS_QUERY_TCPRCVBUF:
                {
					sint32 i_rxbuf_size = 0;
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        i_rxbuf_size);
                    break;
                }
            case E_SHLS_QUERY_TCPRCVDATA:
                {
					sint32 i_rxdata_size = 0;
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        i_rxdata_size);
                    break;
                }
            case E_SHLS_QUERY_TCPRCVFREE:
                {
					sint32 i_rxfree_size = 0;
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,%d,%d",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i_id_socket,
                        i_query_type,
                        i_rxfree_size);
                    break;
                }
            default:
                {
                    OS_DBG_LOG(("lxzat_plus_mipquery_req,i_query_type=%d\r\n",i_query_type));
                    return E_LEC_ERR_P_NB_PARAM;
                    break;
                }
            }
            
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}


/*
 *  Description:
 *    The response handler of "AT+MIPQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipquery_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_id_socket = 0;
    sint32 i_urc_view = LXZAT_FALSE;
    sint32 i_urc_read = LXZAT_SHLS_URCREAD_DEF;
    sint32 i_urc_time = 0;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mipquery_resp,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mipquery_resp,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>[,QueryType]",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MIPQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mipquery_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT+MDNSQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mdnsquery_init(void * pctxt)
{
    LXZAT_ERROR_CODE_E e_err_code = E_LEC_ERR_MEM_NOT_ENOUGH;

    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    lxzat_resp_mdnsquery_t * p_mdnsquery_resp = NULL;

    if (p_lxzat_ctxt != NULL)
    {
        p_mdnsquery_resp = (lxzat_resp_mdnsquery_t *)malloc(sizeof(lxzat_resp_mdnsquery_t));
        if (p_mdnsquery_resp != NULL)
        {
            memset(p_mdnsquery_resp, 0, sizeof(lxzat_resp_mdnsquery_t));
            p_lxzat_ctxt->pt_rsp_data = p_mdnsquery_resp;

            e_err_code = E_LEC_OK;
        }
    }

    return e_err_code;
}

/*
 *  Description:
 *    The request handler of "AT+MDNSQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mdnsquery_req(void * pctxt)
{
    LXZAT_ERROR_CODE_E e_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_resp_mdnsquery_t * p_mdnsquery_resp = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mdnsquery_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mdnsquery_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_id_pdpctxt = 0;
            sint32 i_cur_pdpstatus = 0;
            sint08 p_ip_buf[LXZAT_SHLS_IPSTRING_MAX];
            sint08 p_url_buf[LXZAT_SHLS_URLSTRING_MAX];

            if (p_cur_req->it_nb_param != 2)
            {
                OS_DBG_LOG(("lxzat_plus_mdnsquery_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }

            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_plus_mdnsquery_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_id_pdpctxt = PARAM1(p_cur_req).it_number;
            if(i_id_pdpctxt < 0 || i_id_pdpctxt > LXZAT_MAX_CID_ALLOWED)
            {
                OS_DBG_LOG(("lxzat_plus_mdnsquery_req,i_id_pdpctxt=%d\r\n",i_id_pdpctxt));
                return E_LEC_ERR_P_RANGE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_plus_mdnsquery_req,param2 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }

            memset(p_url_buf, 0, LXZAT_SHLS_URLSTRING_MAX);
            lxz_dstring_get(PARAM2(p_cur_req).pt_str, p_url_buf, LXZAT_SHLS_URLSTRING_MAX);

            lxzat_pdpinfo_f_getstatus(i_id_pdpctxt, &i_cur_pdpstatus);
            if (E_PDP_STATUS_ACTIVATED != i_cur_pdpstatus)
            {
                OS_DBG_LOG(("lxzat_plus_mdnsquery_req,i_cur_pdpstatus=%d\r\n",i_cur_pdpstatus));
                return E_LEC_ERR_PDP_OTHER;
            }

            memset(p_ip_buf, 0, LXZAT_SHLS_IPSTRING_MAX);
            if(osp_gethostbyname(p_url_buf, p_ip_buf) != 1)
            {
                OS_DBG_LOG(("lxzat_plus_mdnsquery_req, gethostbyname error\r\n"));
                return E_LEC_SGCC_DNS_TIMEOUT;
            }

            /* step2: find and match, get IP address */
            p_mdnsquery_resp = ((lxzat_resp_mdnsquery_t *)(p_lxzat_ctxt->pt_rsp_data));
            if (p_mdnsquery_resp != NULL)
            {
                p_mdnsquery_resp->i_got_flag = LXZAT_TRUE;
                p_mdnsquery_resp->i_pdp_id = i_id_pdpctxt;
                sprintf(p_mdnsquery_resp->u_ipaddr_buf, "%s", p_ip_buf);
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            e_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return e_err_code;
}

/*
 *  Description:
 *    The response handler of "AT+MDNSQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mdnsquery_resp(void * pctxt)
{
    LXZAT_ERROR_CODE_E e_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_resp_mdnsquery_t * p_mdnsquery_resp = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_plus_mdnsquery_resp,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_plus_mdnsquery_resp,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            p_mdnsquery_resp = ((lxzat_resp_mdnsquery_t *)(p_lxzat_ctxt->pt_rsp_data));
            if (   (p_mdnsquery_resp != NULL)
                && (p_mdnsquery_resp->i_got_flag = LXZAT_TRUE))
            {
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P1N0,
                    "%s: %d,\"%s\"",
                    p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                    p_mdnsquery_resp->i_pdp_id,
                    p_mdnsquery_resp->u_ipaddr_buf);
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <CID>,<\"DomainName\">",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            break;
        }
    default:
        {
            e_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return e_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT+MDNSQUERY".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_plus_mdnsquery_reset(void * pctxt)
{
    LXZAT_ERROR_CODE_E e_err_code = E_LEC_ERR_MEM_NOT_ENOUGH;

    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    lxzat_resp_mdnsquery_t * p_mdnsquery_resp = NULL;

    if (p_lxzat_ctxt != NULL)
    {
        p_mdnsquery_resp = ((lxzat_resp_mdnsquery_t *)(p_lxzat_ctxt->pt_rsp_data));
        if (p_mdnsquery_resp != NULL)
        {
            free(p_mdnsquery_resp);
            p_mdnsquery_resp = NULL;

            e_err_code = E_LEC_OK;
        }
    }

    return e_err_code;
}

static sint32 lxzat_lsip_socket_f_close(sint32 i_id_socket)
{
    sint32 i_op_status = LXZAT_FALSE;
	lxzat_lsip_socket_t * p_lsip_socket = NULL;

	if(i_id_socket < 0 || i_id_socket > LXZAT_SHLS_MAX_NUM)
	{
		OS_DBG_LOG(("lxzat_lsip_socket_f_close,i_id_socket=%d\r\n", i_id_socket));
		return i_op_status;
	}

	p_lsip_socket = p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
	if(p_lsip_socket->pt_rxbuf != NULL)
	{
		free(p_lsip_socket->pt_rxbuf);
		p_lsip_socket->pt_rxbuf = NULL;
	}
	
	if(p_lsip_socket->pt_txbuf != NULL)
	{
		free(p_lsip_socket->pt_txbuf);
		p_lsip_socket->pt_txbuf = NULL;
	}
	
	if(p_lsip_socket->pt_peer_ip != NULL)
	{
		free(p_lsip_socket->pt_peer_ip);
		p_lsip_socket->pt_peer_ip = NULL;
	}
	
	if(p_lsip_socket->pt_peer_url != NULL)
	{
		free(p_lsip_socket->pt_peer_url);
		p_lsip_socket->pt_peer_url = NULL;
	}

	if(p_lsip_socket->pt_local_ip!= NULL)
	{
		free(p_lsip_socket->pt_local_ip);
		p_lsip_socket->pt_local_ip = NULL;
	}

	if(p_lsip_socket->it_socket_fd != LXZAT_SHLS_INVALID_FD)
	{
		osp_socket_f_close(p_lsip_socket->it_socket_fd);
		p_lsip_socket->it_socket_fd = LXZAT_SHLS_INVALID_FD;
	}
	
	memset(p_lsip_socket, 0, sizeof(lxzat_lsip_socket_t));
	p_lsip_socket->it_socket_fd = LXZAT_SHLS_INVALID_FD;
    p_lsip_socket->it_flag_urcflag = LXZAT_FALSE;
    p_lsip_socket->it_mode_urcview = LXZAT_FALSE;
    p_lsip_socket->it_byte_urctryread = LXZAT_SHLS_URCREAD_DEF;
    p_lsip_socket->it_interval_urctryread = 200;
	i_op_status = LXZAT_TRUE;

	return i_op_status;
}

static sint32 lxzat_callback_mipcall_f_exec(sint32 p1, sint32 p2)
{
    sint32 i_op_status = 1;
    sint32 i_id_vspctxt = 0;
    sint32 i_id_pdpctxt = 0;
    sint32 i_id_sgccpdpctxt = 0;

    sint32 i_cur_pdpstatus = 0;

    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_nvcfg_t * p_cur_nvcfg = NULL;
    sint08 ll_buf_ipaddr [LXZAT_MAX_LEN_IPV4];

    i_id_vspctxt = p1;
    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    p_cur_nvcfg = p_cur_spcfg->pt_nv_cfg;
    if (p_cur_spcfg == NULL)
    {
        return 0;
    }

    i_id_pdpctxt = p2;
    lxzat_pdpinfo_f_getstatus(i_id_pdpctxt, &i_cur_pdpstatus);
    if (E_PDP_STATUS_ACTIVATED == i_cur_pdpstatus)
    {
        i_op_status = 0;
        i_id_sgccpdpctxt = i_id_pdpctxt;
        lxzat_pdpinfo_f_getipaddress(i_id_pdpctxt, ll_buf_ipaddr);

        lxzat_urc_f_printf(i_id_vspctxt, 
            LXZAT_RSP_MODE_P1N1, 
            "+MIPCALL: %d,%d,\"%s\"", 
            i_id_sgccpdpctxt,
            1,
            ll_buf_ipaddr);
    }

    return i_op_status;
}

static sint32 lxzat_callback_mipcall_f_exit(sint32 p1, sint32 p2)
{
    OS_DBG_LOG(("lxzat:lxzat_callback_mipcall_f_exit\r\n"));
    return 1;
}

/*
 *  Description:
 *    new task, mipcall task.
 *  Param: i_id_vspctxt, the ID of serial-port;
 *  Param: i_id_vspctxt, the ID of pdp-context;
 *
 *  Return: status of operating.
 */
static sint32 lxzat_task_mipcall_newtask(sint32 i_id_vspctxt, sint32 i_id_pdpctxt)
{
    sint32 i_op_status = 0;

    lxzat_task_t *p_new_task = NULL;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipcall_newtask,i_id_vspctxt=%d\r\n", i_id_vspctxt));
        return i_op_status;
    }

    if ((i_id_pdpctxt < 0) || (i_id_pdpctxt > 15))
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipcall_newtask,i_id_pdpctxt=%d\r\n", i_id_pdpctxt));
        return i_op_status;
    }

    OS_DBG_LOG(("lxzat:lxzat_task_mipcall_newtask,entry\r\n"));
    OS_DBG_LOG(("lxzat:lxzat_task_mipcall_newtask,i_id_vspctxt=%d,i_id_pdpctxt=%d\r\n", i_id_vspctxt, i_id_pdpctxt));
    p_new_task = (lxzat_task_t *)malloc(sizeof(lxzat_task_t));
    if(p_new_task == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipcall_newtask,p_new_task==NULL!\r\n"));
        return i_op_status;
    }

    i_op_status = 1;
    memset(p_new_task, 0, sizeof(lxzat_task_t));
    p_new_task->fp_exec = lxzat_callback_mipcall_f_exec;
    p_new_task->fp_exit = lxzat_callback_mipcall_f_exit;
    p_new_task->sparam1 = i_id_vspctxt;
    p_new_task->sparam2 = i_id_pdpctxt;
    p_new_task->next = NULL;
    lxzat_task_f_create(p_new_task);

    return i_op_status;
}

static sint32 lxzat_callback_mipdata_tcplink_f_exec(sint32 p1, sint32 p2)
{
    sint32 i_op_status = 0;

    sint32 i_nb_fds = 0;
    sint32 i_nb_bytes_read = 0;
    sint32 i_nb_bytes_available = 0;

    uint32 i_cur_ticks = 0;
    
    sint32 i_id_socket = 0;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    i_id_socket = p1;
    if ((i_id_socket < 0) || (i_id_socket > LXZAT_SHLS_MAX_NUM))
    {
        return i_op_status;
    }

    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
    if (p_lsip_socket == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,i_id_socket=%d,p_lsip_socket==NULL\r\n", i_id_socket));
        return i_op_status;
    }

    p_cur_spcfg = lxzat_spcomm_f_get(p_lsip_socket->it_vsp_id);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,i_id_socket=%d,p_cur_spcfg==NULL\r\n", i_id_socket));
        return i_op_status;
    }
    
    if (p_lsip_socket->it_socket_fd == 0)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,it_socket_fd=%d\r\n", p_lsip_socket->it_socket_fd));
        return i_op_status;
    }

    if (p_lsip_socket->it_socket_phase <= E_SHLS_SOCKET_CONNECTING)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
        return i_op_status;
    }

    if (p_lsip_socket->it_link_type != E_SHLS_LINK_TCP)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,it_net_type=%d\r\n", p_lsip_socket->it_link_type));
        return i_op_status;
    }

    if (p_lsip_socket->it_socket_phase < E_SHLS_SOCKET_ACTIVE)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
        return i_op_status;
    }

    i_cur_ticks = osp_time_tickget();
    if ((p_lsip_socket->it_lasttick_urctryread + p_lsip_socket->it_interval_urctryread) > i_cur_ticks)
    {        
        i_op_status = 1;
        return i_op_status;
    }

    p_lsip_socket->it_lasttick_urctryread = i_cur_ticks;
    if (   (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_ACTIVE)
        || (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_SENDING))
    {
        sint32 i_nb_bytes_available = 0;
        i_nb_bytes_available = osp_socket_f_getavailable(p_lsip_socket->it_socket_fd);
        if (i_nb_bytes_available > 0)
        {
            memset(p_lsip_socket->pt_rxbuf,0,LXZAT_SHLS_URCREAD_DEF);
            i_nb_bytes_read = osp_socket_f_read(p_lsip_socket->it_socket_fd,
                p_lsip_socket->pt_rxbuf,LXZAT_SHLS_URCREAD_DEF);
            
            OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,i_cur_ticks=%d\r\n", p_lsip_socket->it_lasttick_urctryread));
            lxzat_rsp_f_printf(p_lsip_socket->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "+MIPDATA: %d,%d,",
                i_id_socket,
                i_nb_bytes_read);

            lxzat_spcomm_f_writebyid(p_lsip_socket->it_vsp_id,
                p_lsip_socket->pt_rxbuf, i_nb_bytes_read);
            lxzat_spcomm_f_writebyid(p_lsip_socket->it_vsp_id,
                "\r\n", 2);
            lxzat_spcomm_f_flush(p_lsip_socket->it_vsp_id);
        }

        i_nb_fds = osp_socket_f_select(p_lsip_socket->it_socket_fd, OSP_EVENT_READ, 0);
        if (i_nb_fds > 0)
        {
            i_nb_bytes_available = osp_socket_f_getavailable(p_lsip_socket->it_socket_fd);
            if (i_nb_bytes_available == 0)
            {
                p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_CLOSING;
                OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,i_id_socket=%d, closed!\r\n", i_id_socket));
            }
        }
    }

    if (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_CLOSING)
    {
        i_nb_bytes_available = osp_socket_f_getavailable(p_lsip_socket->it_socket_fd);
        if (i_nb_bytes_available <= 0)
        {
            lxzat_urc_f_printf(p_lsip_socket->it_vsp_id, LXZAT_RSP_MODE_P1N1, "+MIPCLOSE: %d", i_id_socket);

            lxzat_spcomm_f_clear(p_lsip_socket->it_vsp_id);
            lxzat_spcomm_f_ChangeWorkMode(p_lsip_socket->it_vsp_id,
                E_LSMX_ATC, LXZAT_END_CHAR_CR, LXZAT_END_CHAR_LF);
            lxzat_lsip_socket_f_close(i_id_socket);
            OS_DBG_LOG(("lxzat_callback_mipdata_tcplink_f_exec,i_id_socket=%d, closed!\r\n", i_id_socket));
        }
    }

    i_op_status = 1;
    return i_op_status;
}

static sint32 lxzat_callback_mipdata_tcplink_f_exit(sint32 p1, sint32 p2)
{
    OS_DBG_LOG(("lxzat:lxzat_callback_mipdata_tcplink_f_exit\r\n"));
    return 1;
}

/*
 *  Description:
 *    new task, mipdata-client task.
 *  Param: i_id_vspctxt, the ID of serial-port;
 *  Param: i_id_vspctxt, the ID of pdp-context;
 *
 *  Return: status of operating.
 */
static sint32 lxzat_task_mipdata_tcplink_newtask(sint32 i_id_socket, sint32 i_id_vspctxt)
{
    sint32 i_op_status = 0;

    lxzat_task_t *p_new_task = NULL;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipdata_newtask,i_id_vspctxt=%d\r\n", i_id_vspctxt));
        return i_op_status;
    }

    OS_DBG_LOG(("lxzat:lxzat_task_mipdata_newtask,entry\r\n"));
    OS_DBG_LOG(("lxzat:lxzat_task_mipdata_newtask,i_id_socket=%d,i_id_vspctxt=%d\r\n", i_id_socket, i_id_vspctxt));
    p_new_task = (lxzat_task_t *)malloc(sizeof(lxzat_task_t));
    if(p_new_task == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipdata_newtask,p_new_task==NULL!\r\n"));
        return i_op_status;
    }

    i_op_status = 1;
    memset(p_new_task, 0, sizeof(lxzat_task_t));
    p_new_task->fp_exec = lxzat_callback_mipdata_tcplink_f_exec;
    p_new_task->fp_exit = lxzat_callback_mipdata_tcplink_f_exit;
    p_new_task->sparam1 = i_id_socket;
    p_new_task->sparam2 = i_id_vspctxt;
    p_new_task->next = NULL;
    lxzat_task_f_create(p_new_task);

    return i_op_status;
}

static sint32 lxzat_callback_mipdata_udplink_f_exec(sint32 p1, sint32 p2)
{
    sint32 i_op_status = 0;

    sint32 i_nb_fds = 0;
    sint32 i_nb_bytes_read = 0;
    sint32 i_nb_bytes_available = 0;
    
    sint32 i_id_socket = 0;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    i_id_socket = p1;
    if ((i_id_socket < 0) || (i_id_socket > LXZAT_SHLS_MAX_NUM))
    {
        return i_op_status;
    }

    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
    if (p_lsip_socket == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_udplink_f_exec,i_id_socket=%d,p_lsip_socket==NULL\r\n", i_id_socket));
        return i_op_status;
    }

    p_cur_spcfg = lxzat_spcomm_f_get(p_lsip_socket->it_vsp_id);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_udplink_f_exec,i_id_socket=%d,p_cur_spcfg==NULL\r\n", i_id_socket));
        return i_op_status;
    }
    
    if (p_lsip_socket->it_socket_fd == 0)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_udplink_f_exec,it_socket_fd=%d\r\n", p_lsip_socket->it_socket_fd));
        return i_op_status;
    }

    if (p_lsip_socket->it_socket_phase <= E_SHLS_SOCKET_CONNECTING)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_udplink_f_exec,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
        return i_op_status;
    }

    if (p_lsip_socket->it_link_type != E_SHLS_LINK_UDP)
    {
        OS_DBG_LOG(("lxzat_callback_mipdata_udplink_f_exec,it_net_type=%d\r\n", p_lsip_socket->it_link_type));
        return i_op_status;
    }

    if (   (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_ACTIVE)
        || (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_SENDING))
    {
        memset(p_lsip_socket->pt_rxbuf,0,LXZAT_SHLS_URCREAD_DEF);
        i_nb_bytes_read = osp_socket_f_readfrom(p_lsip_socket->it_socket_fd, 
            p_lsip_socket->pt_rxbuf, LXZAT_SHLS_URCREAD_DEF);
        
        lxzat_rsp_f_printf(p_lsip_socket->it_vsp_id,
            LXZAT_RSP_MODE_P1N0,
            "+MIPDATA: %d,%d,",
            i_id_socket,
            i_nb_bytes_read);
        
        lxzat_spcomm_f_writebyid(p_lsip_socket->it_vsp_id,
            p_lsip_socket->pt_rxbuf, i_nb_bytes_read);
        lxzat_spcomm_f_writebyid(p_lsip_socket->it_vsp_id,
            "\r\n", 2);
        lxzat_spcomm_f_flush(p_lsip_socket->it_vsp_id);
    }

    i_op_status = 1;
    return i_op_status;
}

static sint32 lxzat_callback_mipdata_udplink_f_exit(sint32 p1, sint32 p2)
{
    OS_DBG_LOG(("lxzat:lxzat_callback_mipdata_udplink_f_exit\r\n"));
    return 1;
}

/*
 *  Description:
 *    new task, mipdata-udplink task.
 *  Param: i_id_vspctxt, the ID of serial-port;
 *  Param: i_id_vspctxt, the ID of pdp-context;
 *
 *  Return: status of operating.
 */
static sint32 lxzat_task_mipdata_udplink_newtask(sint32 i_id_socket, sint32 i_id_vspctxt)
{
    sint32 i_op_status = 0;

    lxzat_task_t *p_new_task = NULL;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipdata_udplink_newtask,i_id_vspctxt=%d\r\n", i_id_vspctxt));
        return i_op_status;
    }

    OS_DBG_LOG(("lxzat:lxzat_task_mipdata_udplink_newtask,entry\r\n"));
    OS_DBG_LOG(("lxzat:lxzat_task_mipdata_udplink_newtask,i_id_socket=%d,i_id_vspctxt=%d\r\n", i_id_socket, i_id_vspctxt));
    p_new_task = (lxzat_task_t *)malloc(sizeof(lxzat_task_t));
    if(p_new_task == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipdata_udplink_newtask,p_new_task==NULL!\r\n"));
        return i_op_status;
    }

    i_op_status = 1;
    memset(p_new_task, 0, sizeof(lxzat_task_t));
    p_new_task->fp_exec = lxzat_callback_mipdata_udplink_f_exec;
    p_new_task->fp_exit = lxzat_callback_mipdata_udplink_f_exit;
    p_new_task->sparam1 = i_id_socket;
    p_new_task->sparam2 = i_id_vspctxt;
    p_new_task->next = NULL;
    lxzat_task_f_create(p_new_task);

    return i_op_status;
}

static sint32 lxzat_callback_mipclose_f_exec(sint32 p1, sint32 p2)
{
    sint32 i_op_status = 0;

    sint32 i_nb_fds = 0;
    sint32 i_nb_bytes_read = 0;
    sint32 i_nb_bytes_available = 0;
    
    sint32 i_id_socket = 0;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_lsip_socket_t * p_lsip_socket = NULL;
    
    i_id_socket = p1;
    if ((i_id_socket < 0) || (i_id_socket > LXZAT_SHLS_MAX_NUM))
    {
        return i_op_status;
    }

    p_lsip_socket = &(gs_lsip_socket_pool[i_id_socket]);
    if (p_lsip_socket == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,i_id_socket=%d,p_lsip_socket==NULL\r\n", i_id_socket));
        return i_op_status;
    }

    p_cur_spcfg = lxzat_spcomm_f_get(p_lsip_socket->it_vsp_id);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,i_id_socket=%d,p_cur_spcfg==NULL\r\n", i_id_socket));
        return i_op_status;
    }
    
    if (p_lsip_socket->it_socket_fd == 0)
    {
        OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,it_socket_fd=%d\r\n", p_lsip_socket->it_socket_fd));
        return i_op_status;
    }

    if (p_lsip_socket->it_socket_phase <= E_SHLS_SOCKET_CONNECTING)
    {
        OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,it_socket_phase=%d\r\n", p_lsip_socket->it_socket_phase));
        return i_op_status;
    }

    if (p_lsip_socket->it_link_type != E_SHLS_LINK_TCP)
    {
        OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,it_net_type=%d\r\n", p_lsip_socket->it_link_type));
        return i_op_status;
    }

    if (   (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_ACTIVE)
        || (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_SENDING))
    {
        i_nb_fds = osp_socket_f_select(p_lsip_socket->it_socket_fd, OSP_EVENT_READ, 0);
        if (i_nb_fds > 0)
        {
            i_nb_bytes_available = osp_socket_f_getavailable(p_lsip_socket->it_socket_fd);
            if (i_nb_bytes_available == 0)
            {
                p_lsip_socket->it_socket_phase = E_SHLS_SOCKET_CLOSING;
                OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,i_id_socket=%d, closed!\r\n", i_id_socket));
            }
        }
    }

    if (p_lsip_socket->it_socket_phase == E_SHLS_SOCKET_CLOSING)
    {
        i_nb_bytes_available = osp_socket_f_getavailable(p_lsip_socket->it_socket_fd);
        if (i_nb_bytes_available <= 0)
        {
            lxzat_urc_f_printf(p_lsip_socket->it_vsp_id, LXZAT_RSP_MODE_P1N1, "+MIPCLOSE: %d", i_id_socket);

            lxzat_spcomm_f_clear(p_lsip_socket->it_vsp_id);
            lxzat_spcomm_f_ChangeWorkMode(p_lsip_socket->it_vsp_id,
                E_LSMX_ATC, LXZAT_END_CHAR_CR, LXZAT_END_CHAR_LF);
            lxzat_lsip_socket_f_close(i_id_socket);
            OS_DBG_LOG(("lxzat_callback_mipclose_f_exec,i_id_socket=%d, closed!\r\n", i_id_socket));
        }
    }

    i_op_status = 1;
    return i_op_status;
}

static sint32 lxzat_callback_mipclose_f_exit(sint32 p1, sint32 p2)
{
    OS_DBG_LOG(("lxzat:lxzat_callback_mipclose_f_exit\r\n"));
    return 1;
}

/*
 *  Description:
 *    new task, mipclose task.
 *  Param: i_id_vspctxt, the ID of serial-port;
 *  Param: i_id_vspctxt, the ID of pdp-context;
 *
 *  Return: status of operating.
 */
static sint32 lxzat_task_mipclose_newtask(sint32 i_id_socket, sint32 i_id_vspctxt)
{
    sint32 i_op_status = 0;

    lxzat_task_t *p_new_task = NULL;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipclose_newtask,i_id_vspctxt=%d\r\n", i_id_vspctxt));
        return i_op_status;
    }

    OS_DBG_LOG(("lxzat:lxzat_task_mipclose_newtask,entry\r\n"));
    OS_DBG_LOG(("lxzat:lxzat_task_mipclose_newtask,i_id_socket=%d,i_id_vspctxt=%d\r\n", i_id_socket, i_id_vspctxt));
    p_new_task = (lxzat_task_t *)malloc(sizeof(lxzat_task_t));
    if(p_new_task == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_mipclose_newtask,p_new_task==NULL!\r\n"));
        return i_op_status;
    }

    i_op_status = 1;
    memset(p_new_task, 0, sizeof(lxzat_task_t));
    p_new_task->fp_exec = lxzat_callback_mipclose_f_exec;
    p_new_task->fp_exit = lxzat_callback_mipclose_f_exit;
    p_new_task->sparam1 = i_id_socket;
    p_new_task->sparam2 = i_id_vspctxt;
    p_new_task->next = NULL;
    lxzat_task_f_create(p_new_task);

    return i_op_status;
}
